var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
let cors = require('cors');
let mysql = require('mysql');
let courseListRouter = require('./routes/courseList');
const indexRouter=require('./routes/index');
const searchListRouter=require('./routes/searchlist');
let userRoutes = require('./routes/users')
let infoRouter  = require('./routes/courseinfo')


var app = express();
app.use(cors());

// view engine setup
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'ejs');


app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use(cookieParser());

app.use('/public',express.static(path.join(__dirname, 'public')));
app.use('/uploads',express.static(path.join(__dirname, 'uploads')));
app.use('/project_render',express.static(path.join(__dirname,'../project_render')));
// 使用路由
app.use('/api', courseListRouter);
app.use('/api', indexRouter);
app.use('/api', searchListRouter);
app.use('/api',userRoutes)
app.use('/api',infoRouter);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
  res.send({code:404,msg:'404,丢了'})
});

// error handler
app.use(function(err, req, res, next) {
  res.send(err);//next({code:500,msg:'neirong'})
});

module.exports = app;
